using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;

using GonzalesCore.CoreElements;
using GonzalesCore.CoreManagers;
using Kypris2.CoreElements;
using Kypris2.Utils;
using Jamila2.Tools;

public partial class GonzalesAdminEEDLDetail : System.Web.UI.Page
{
    #region Variables

    protected PrivateLoginSession CurrentPrivateSession = null;
    protected LogManager CurLogManager = null;
    protected DataObj CurPageDataObj = new DataObj();    

    #region ClaimantID
    protected string ClaimantID
    {
        get
        {
            return (ViewState["ClaimantID"] != null) ? ViewState["ClaimantID"].ToString() : "";
        }

        set
        {
            ViewState["ClaimantID"] = value;
        }
    }
    #endregion 

    #region CurrentPageIndex
    protected int CurrentPageIndex
    {
        get
        {
            return (int)ViewState["CurrentPageIndex"];
        }

        set
        {
            ViewState["CurrentPageIndex"] = value;
        }
    }
    #endregion

    #region ResultTable
    protected DataTable ResultTable
    {
        get
        {
            return (DataTable)ViewState["ResultTable"];
        }

        set
        {
            ViewState["ResultTable"] = value;
        }
    }
    #endregion

    #region CompanyID
    protected string CompanyID
    {
        get
        {
            return ViewState["CompanyID"].ToString();
        }

        set
        {
            ViewState["CompanyID"] = value;
        }
    }
    #endregion

    #region EntityID
    protected string EntityID
    {
        get
        {
            return ViewState["EntityID"].ToString();
        }

        set
        {
            ViewState["EntityID"] = value;
        }
    }
    #endregion

    #region GridViewHeader
    protected ArrayList GridViewHeader
    {
        get
        {
            return (ArrayList)ViewState["GridViewHeader"];
        }

        set
        {
            ViewState["GridViewHeader"] = value;
        }
    }
    #endregion

    #region SuccessMessage
    protected string SuccessMessage
    {
        get
        {
            return ViewState["SuccessMessage"].ToString();
        }

        set
        {
            ViewState["SuccessMessage"] = value;
        }
    }
    #endregion

    #region ErrorMessage
    protected string ErrorMessage
    {
        get
        {
            return ViewState["ErrorMessage"].ToString();
        }

        set
        {
            ViewState["ErrorMessage"] = value;
        }
    }
    #endregion

    #region FailedLoadMessage
    protected string FailedLoadMessage
    {
        get
        {
            return ViewState["FailedLoadMessage"].ToString();
        }

        set
        {
            ViewState["FailedLoadMessage"] = value;
        }
    }
    #endregion

    #region ClaimantMessage
    protected string ClaimantMessage
    {
        get
        {
            return ViewState["ClaimantMessage"].ToString();
        }

        set
        {
            ViewState["ClaimantMessage"] = value;
        }
    }
    #endregion

    #region LimitAmountMessage
    protected string LimitAmountMessage
    {
        get
        {
            return ViewState["LimitAmountMessage"].ToString();
        }

        set
        {
            ViewState["LimitAmountMessage"] = value;
        }
    }
    #endregion

    #region DuplicateMessage
    protected string DuplicateMessage
    {
        get
        {
            return ViewState["DuplicateMessage"].ToString();
        }

        set
        {
            ViewState["DuplicateMessage"] = value;
        }
    }
    #endregion

    #region DeletionFailedMessage
    protected string DeletionFailedMessage
    {
        get
        {
            return ViewState["DeletionFailedMessage"].ToString();
        }

        set
        {
            ViewState["DeletionFailedMessage"] = value;
        }
    }
    #endregion

    #endregion

    #region Events

    #region Page_Load
    protected void Page_Load(object sender, EventArgs e)
    {
        this.SessionCheck();

        // check if delete
        this.DataDelete();

        if (!IsPostBack)
        {
            if (this.CurrentPrivateSession.CurrentLoggedOnUser.IsFinanceAdmin)
            {
                if (!this.CurrentPrivateSession.CurrentLoggedOnUser.IsFinancialManager)
                {
                    Button_Submit.Visible = false;
                }
            }
            else if (this.CurrentPrivateSession.CurrentLoggedOnUser.IsPowerAdmin || this.CurrentPrivateSession.CurrentLoggedOnUser.IsITAdmin) // thangnv added 20130522
            {
                Button_Submit.Visible = false;
            }

            // page index is 0 at the first load
            this.CurrentPageIndex = 0;

            // get request string
            if (Request.QueryString["id"] != null && Request.QueryString["id"].ToString().Length == 36)
            {
                this.ClaimantID = Request.QueryString["id"];
            }

            // setup
            this.PageComponentSetup();
            this.SwitchLanguage();

            this.LoadData();
            if (this.ResultTable != null)
            {
                this.BindData(new DataView(this.ResultTable));
            }

            // log down the history
            this.CurLogManager.LogMessage("[GonzalesAdminEEDLDetail] : Exception Expense Detail for Claimant(" + this.ClaimantID + ", " + this.LabelValue_DisplayName.Text + ") viewed", this.CurrentPrivateSession.CurrentLoggedOnUser, LogInterface.User);
        }
    }
    #endregion

    #region DropDownList_SortBy_SelectedIndexChanged
    protected void DropDownList_SortBy_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (this.ResultTable != null)
        {
            DataView ResultView = new DataView(this.ResultTable);
            ResultView.Sort = this.DropDownList_SortBy.SelectedValue + " " + this.DropDownList_SortOrder.SelectedValue;
            this.BindData(ResultView, this.CurrentPageIndex);
        }
    }
    #endregion

    #region DropDownList_SortOrder_SelectedIndexChanged
    protected void DropDownList_SortOrder_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (this.ResultTable != null)
        {
            DataView ResultView = new DataView(this.ResultTable);
            ResultView.Sort = this.DropDownList_SortBy.SelectedValue + " " + this.DropDownList_SortOrder.SelectedValue;
            this.BindData(ResultView, this.CurrentPageIndex);
        }
    }
    #endregion

    #region GridViewResult_PageIndexChanging
    protected void GridViewResult_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        if (this.ResultTable != null)
        {
            this.CurrentPageIndex = e.NewPageIndex;

            DataView ResultView = new DataView(this.ResultTable);
            ResultView.Sort = this.DropDownList_SortBy.SelectedValue + " " + this.DropDownList_SortOrder.SelectedValue;
            this.BindData(ResultView, this.CurrentPageIndex);
        }
    }
    #endregion

    #region ImageButton_Cancel_Click
    protected void ImageButton_Cancel_Click(object sender, ImageClickEventArgs e)
    {
        Response.Redirect("GonzalesAdminEEDLListing.aspx?entity=" + this.EntityID + "&company=" + this.CompanyID);
    }
    #endregion

    #region Button_Submit_Click
    protected void Button_Submit_Click(object sender, EventArgs e)
    {
        if (this.DataValidate())
        {
            using (GLClaimTypeManager CurClaimTypeManager = new GLClaimTypeManager(this.CurrentPrivateSession))
            {
                if (CurClaimTypeManager.AddClaimTypeLimit(
                    this.ClaimantID, this.DropDownList_ExpenseDetail.SelectedValue, this.DropDownList_Currency.SelectedValue,
                    decimal.Parse(this.TextBox_AmountLimit.Text), Int32.Parse(this.DropDownList_Duration.SelectedValue), this.CheckBox_Strict.Checked))
                {
                    // log down the history
                    this.CurLogManager.LogMessage("[GonzalesAdminEASDetail.Button_Submit_Click] : New Exception Expense Detail (" + this.DropDownList_ExpenseDetail.SelectedValue + ", " + this.DropDownList_ExpenseDetail.SelectedItem.Text + ") added, to Claimant(" + this.ClaimantID + ", " + this.LabelValue_DisplayName.Text + ")", this.CurrentPrivateSession.CurrentLoggedOnUser, LogInterface.User);

                    this.ShowMessage("Data saved successfully.");

                    this.LoadData();
                    if (this.ResultTable != null)
                    {
                        this.BindData(new DataView(this.ResultTable));
                    }
                }
                else
                {
                    this.ShowErrorMessage("Data saved error.");
                    this.CurLogManager.LogError("[GonzalesAdminEEDLDetail.Button_Submit_Click] : Failed at CurClaimTypeManager.AddClaimTypeLimit() : " + CurClaimTypeManager.ErrorMessage, this.CurrentPrivateSession.CurrentLoggedOnUser, LogInterface.System);
                }
            }
        }
    }
    #endregion

    #region DropDownList_Category_SelectedIndexChanged

    protected void DropDownList_Category_SelectedIndexChanged(object sender, EventArgs e)
    {
        using (UserManager CurUserManager = new UserManager(this.CurrentPrivateSession))
        {
            SystemUser CurUser = CurUserManager.GetUserByInternalID(this.ClaimantID);

            using (GLClaimTypeManager CurClaimTypeManager = new GLClaimTypeManager(this.CurrentPrivateSession))
            {
                MasterBaseCollection ResultCollection = CurClaimTypeManager.GetActiveClaimTypeInLangByEntity(
                    this.CurrentPrivateSession.CurrentLoggedOnUser.PreferedLanguage,
                    CurUser.FromCompany.Entity,
                    this.DropDownList_Category.SelectedValue);

                if (ResultCollection != null)
                {
                    if (ResultCollection.Count > 0)
                    {
                        this.DropDownList_ExpenseDetail.Items.Clear();

                        for (int x = 0; x < ResultCollection.Count; x++)
                        {
                            this.DropDownList_ExpenseDetail.Items.Add(new ListItem(ResultCollection[x].DisplayName, ResultCollection[x].InternalID));
                        }
                    }                    
                }
                else
                {
                    this.CurLogManager.LogError("[GonzalesAdminEEDLDetail.DropDownList_Category_SelectedIndexChanged] : Failed in CurClaimTypeManager.GetActiveClaimTypeInLangByEntity() : " + CurClaimTypeManager.ErrorMessage, this.CurrentPrivateSession.CurrentLoggedOnUser, LogInterface.User);
                }
            }
        }

        if (ClaimManager.GetClaimCategoryFromCode(this.DropDownList_Category.SelectedValue) == CategoryOfClaim.General)
        {
            this.DropDownList_Duration.Items.Clear();
            this.DropDownList_Duration.Items.Add(new ListItem("Daily", ClaimManager.GetClaimTypeLimitDurationInCode(TypeOfClaimLimitDuration.Daily).ToString()));
            this.DropDownList_Duration.Items.Add(new ListItem("Weekly", ClaimManager.GetClaimTypeLimitDurationInCode(TypeOfClaimLimitDuration.Weekly).ToString()));
            this.DropDownList_Duration.Items.Add(new ListItem("Monthly", ClaimManager.GetClaimTypeLimitDurationInCode(TypeOfClaimLimitDuration.Monthly).ToString()));
            this.DropDownList_Duration.Items.Add(new ListItem("Calendar Year", ClaimManager.GetClaimTypeLimitDurationInCode(TypeOfClaimLimitDuration.CalendarYearly).ToString()));
            this.DropDownList_Duration.Items.Add(new ListItem("Fiscal Year", ClaimManager.GetClaimTypeLimitDurationInCode(TypeOfClaimLimitDuration.FiscalYearly).ToString()));

        }
        else if (ClaimManager.GetClaimCategoryFromCode(this.DropDownList_Category.SelectedValue) == CategoryOfClaim.Entertainment)
        {
            this.DropDownList_Duration.Items.Clear();
            this.DropDownList_Duration.Items.Add(new ListItem("Per Event", ClaimManager.GetClaimTypeLimitDurationInCode(TypeOfClaimLimitDuration.PerEvent).ToString()));
        }

    }

    #endregion

    #region OnRowCreated
    protected void OnRowCreated(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.Header)
        {
            TableCellCollection cells = e.Row.Cells;

            for (int i = 0; i < this.GridViewHeader.Count; i++)
            {
                cells[i].Text = this.GridViewHeader[i].ToString();
            }
        }
    }
    #endregion

    #endregion

    #region Customized Methods

    #region SessionCheck
    public void SessionCheck()
    {

        if (Session[GonzalesCommonNamingConvention.CurrentPrivateSession] != null)
        {
            this.CurrentPrivateSession = (PrivateLoginSession)Session[GonzalesCommonNamingConvention.CurrentPrivateSession];
            this.CurLogManager = new LogManager(this.CurrentPrivateSession);    // activate Log Manager
        }
        else
        {
            Response.Redirect(GonzalesErrorPageRedirect.SessionError);
        }

    }
    #endregion

    #region PageComponentSetup
    protected void PageComponentSetup()
    {
        // claimant
        using (UserManager CurUserManager = new UserManager(this.CurrentPrivateSession))
        {
            SystemUser CurUser = CurUserManager.GetUserByInternalID(this.ClaimantID);

            this.LabelValue_EmployeeID.Text = CurUser.EmployeeID;
            this.LabelValue_DisplayName.Text = CurUser.DisplayName;

            // category
            this.DropDownList_Category.Items.Add(new ListItem("General", ClaimManager.GetClaimCategoryInCode(CategoryOfClaim.General).ToString()));
            this.DropDownList_Category.Items.Add(new ListItem("Entertainment", ClaimManager.GetClaimCategoryInCode(CategoryOfClaim.Entertainment).ToString()));
            this.DropDownList_Category.SelectedIndex = 0;   // default

            // expense detail
            using (GLClaimTypeManager CurClaimTypeManager = new GLClaimTypeManager(this.CurrentPrivateSession))
            {
                MasterBaseCollection ResultCollection = CurClaimTypeManager.GetActiveClaimTypeInLangByEntity(
                    this.CurrentPrivateSession.CurrentLoggedOnUser.PreferedLanguage,
                    CurUser.FromCompany.Entity,
                    this.DropDownList_Category.SelectedValue);

                if (ResultCollection != null && ResultCollection.Count > 0)
                {
                    this.DropDownList_ExpenseDetail.Items.Clear();

                    for (int x = 0; x < ResultCollection.Count; x++)
                    {
                        this.DropDownList_ExpenseDetail.Items.Add(new ListItem(ResultCollection[x].DisplayName, ResultCollection[x].InternalID));
                    }
                }
                else
                {
                    this.CurLogManager.LogError("[GonzalesAdminEEDLDetail.PageComponentSetup] : Failed in CurClaimTypeManager.GetActiveClaimTypeInLangByEntity() : " + CurClaimTypeManager.ErrorMessage, this.CurrentPrivateSession.CurrentLoggedOnUser, LogInterface.User);
                }
            }

            // currency
            using (CurrencyManager CurCurrencyManager = new CurrencyManager(this.CurrentPrivateSession))
            {
                MasterBaseCollection ResultCollection = CurCurrencyManager.GetAllCurrency();

                if (ResultCollection != null && ResultCollection.Count > 0)
                {
                    this.DropDownList_Currency.Items.Clear();

                    for (int x = 0; x < ResultCollection.Count; x++)
                    {
                        this.DropDownList_Currency.Items.Add(new ListItem(ResultCollection[x].DisplayName, ResultCollection[x].InternalID));
                    }
                }
                else
                {
                    this.CurLogManager.LogError("[GonzalesAdminEEDLDetail.PageComponentSetup] : Failed in CurCurrencyManager.GetAllCurrency() : " + CurCurrencyManager.ErrorMessage, this.CurrentPrivateSession.CurrentLoggedOnUser, LogInterface.User);
                }

                this.DropDownList_Currency.Items.FindByValue(CurUser.DefaultCurrency.InternalID).Selected = true;
            }

        }

        // cancel button
        this.ImageButton_Cancel.Attributes["onclick"] = "return confirm('All unsaved data will be lost, are you sure?');";
    }
    #endregion

    #region SwitchLanguage
    protected void SwitchLanguage()
    {
        try
        {
            using (MultiLingualFactory CurLanguageFactory = MultiLingualEngine.GetMultiLingualFactory(this, this.CurrentPrivateSession.CurrentLoggedOnUser.PreferedLanguage.InternalID))
            {
                this.Label_Category.Text = CurLanguageFactory.DisplayValue("Category");
                this.Label_EmployeeID.Text = CurLanguageFactory.DisplayValue("EmployeeID");
                this.Label_ExpenseDetail.Text = CurLanguageFactory.DisplayValue("ExpenseDetail2");
                this.Label_Information.Text = CurLanguageFactory.DisplayValue("Information");
                this.Label_LimitAmount.Text = CurLanguageFactory.DisplayValue("LimitAmount");
                this.Label_LimitDuration.Text = CurLanguageFactory.DisplayValue("LimitDuration");
                this.Label_Name.Text = CurLanguageFactory.DisplayValue("Name");
                this.Label_PageTitle.Text = CurLanguageFactory.DisplayValue("PageTitle");
                this.Label_Strict.Text = CurLanguageFactory.DisplayValue("Label_Strict");
                this.Button_Submit.Text = CurLanguageFactory.DisplayValue("Submit");
                this.SuccessMessage = CurLanguageFactory.DisplayValue("SuccessMessage");
                this.FailedLoadMessage = CurLanguageFactory.DisplayValue("FailedLoadMessage");
                this.ErrorMessage = CurLanguageFactory.DisplayValue("ErrorMessage");
                this.ClaimantMessage = CurLanguageFactory.DisplayValue("ClaimantMessage");
                this.LimitAmountMessage = CurLanguageFactory.DisplayValue("LimitAmountMessage");
                this.DuplicateMessage = CurLanguageFactory.DisplayValue("DuplicateMessage");
                this.DeletionFailedMessage = CurLanguageFactory.DisplayValue("DeletionFailedMessage");

                this.GridViewHeader = new ArrayList();
                this.GridViewHeader.Add(CurLanguageFactory.DisplayValue("Code"));
                this.GridViewHeader.Add(CurLanguageFactory.DisplayValue("ExpenseDetail"));
                this.GridViewHeader.Add(CurLanguageFactory.DisplayValue("DurationInString"));
                this.GridViewHeader.Add(CurLanguageFactory.DisplayValue("Strict"));
                this.GridViewHeader.Add(CurLanguageFactory.DisplayValue("Currency"));
                this.GridViewHeader.Add(CurLanguageFactory.DisplayValue("LimitAmountInStr"));


                // duration        
                this.DropDownList_Duration.Items.Add(new ListItem(CurLanguageFactory.DisplayValue("Daily"), ClaimManager.GetClaimTypeLimitDurationInCode(TypeOfClaimLimitDuration.Daily).ToString()));
                this.DropDownList_Duration.Items.Add(new ListItem(CurLanguageFactory.DisplayValue("Weekly"), ClaimManager.GetClaimTypeLimitDurationInCode(TypeOfClaimLimitDuration.Weekly).ToString()));
                this.DropDownList_Duration.Items.Add(new ListItem(CurLanguageFactory.DisplayValue("Monthly"), ClaimManager.GetClaimTypeLimitDurationInCode(TypeOfClaimLimitDuration.Monthly).ToString()));
                this.DropDownList_Duration.Items.Add(new ListItem(CurLanguageFactory.DisplayValue("CalendarYear"), ClaimManager.GetClaimTypeLimitDurationInCode(TypeOfClaimLimitDuration.CalendarYearly).ToString()));
                this.DropDownList_Duration.Items.Add(new ListItem(CurLanguageFactory.DisplayValue("FiscalYear"), ClaimManager.GetClaimTypeLimitDurationInCode(TypeOfClaimLimitDuration.FiscalYearly).ToString()));

                this.DropDownList_SortBy.Items.Add(new ListItem(CurLanguageFactory.DisplayValue("Code"), this.CurPageDataObj.Code));
                this.DropDownList_SortBy.Items.Add(new ListItem(CurLanguageFactory.DisplayValue("ExpenseDetail"), this.CurPageDataObj.ExpenseDetail));

                this.DropDownList_SortOrder.Items.Add(new ListItem(CurLanguageFactory.DisplayValue("ASC"), "ASC"));
                this.DropDownList_SortOrder.Items.Add(new ListItem(CurLanguageFactory.DisplayValue("DESC"), "DESC"));

            }
        }
        catch (Exception ex)
        {
            this.CurLogManager.LogError("[GonzalesAdminClaimantsDetail.SwitchLanguage.EX] : " + ex.Message, this.CurrentPrivateSession.CurrentLoggedOnUser, LogInterface.User);
        }

    }
    #endregion

    #region ShowErrorMessage
    protected void ShowErrorMessage(string ErrorMessage)
    {
        this.Table_MessageBox.Visible = true;
        this.Table_MessageBox.Rows[0].Cells[0].Text = ErrorMessage;
        this.Table_MessageBox.Rows[0].Cells[0].CssClass = "ErrorBox";
    }
    #endregion

    #region ShowMessage
    protected void ShowMessage(string Message)
    {
        this.Table_MessageBox.Visible = true;
        this.Table_MessageBox.Rows[0].Cells[0].Text = Message;
        this.Table_MessageBox.Rows[0].Cells[0].CssClass = "MessageBox";
    }
    #endregion

    #endregion

    #region Data Operation

    #region LoadData
    protected void LoadData()
    {
        if (this.ClaimantID.Length == 36)
        {
            using (UserManager CurUserManager = new UserManager(this.CurrentPrivateSession))
            {
                SystemUser CurUser = CurUserManager.GetUserByInternalID(this.ClaimantID);
                if (CurUser != null)
                {
                    this.CompanyID = CurUser.FromCompany.InternalID;
                    this.EntityID = CurUser.FromCompany.Entity.InternalID;
                }
            }

            using (GLClaimTypeManager CurManager = new GLClaimTypeManager(this.CurrentPrivateSession))
            {
                MasterBaseCollection ResultCollection = CurManager.GetClaimTypeLimitByClaimant(this.ClaimantID, this.CurrentPrivateSession.CurrentLoggedOnUser.PreferedLanguage.InternalID);

                if (ResultCollection != null)
                {
                    this.ResultTable = new DataTable();
                    
                    ResultTable.Columns.Add(new DataColumn(this.CurPageDataObj.InternalID, Type.GetType("System.String")));                    
                    ResultTable.Columns.Add(new DataColumn(this.CurPageDataObj.Code, Type.GetType("System.String")));
                    ResultTable.Columns.Add(new DataColumn(this.CurPageDataObj.DurationInString, Type.GetType("System.String")));
                    ResultTable.Columns.Add(new DataColumn(this.CurPageDataObj.Currency, Type.GetType("System.String")));
                    ResultTable.Columns.Add(new DataColumn(this.CurPageDataObj.LimitAmount, Type.GetType("System.Decimal")));
                    ResultTable.Columns.Add(new DataColumn(this.CurPageDataObj.LimitAmountInStr, Type.GetType("System.String")));
                    ResultTable.Columns.Add(new DataColumn(this.CurPageDataObj.Strict, Type.GetType("System.String")));
                    ResultTable.Columns.Add(new DataColumn(this.CurPageDataObj.ExpenseDetail, Type.GetType("System.String")));
                    ResultTable.Columns.Add(new DataColumn(this.CurPageDataObj.EditLink, Type.GetType("System.String")));
                    ResultTable.Columns.Add(new DataColumn(this.CurPageDataObj.DeleteLink, Type.GetType("System.String")));

                    for (int x = 0; x < ResultCollection.Count; x++)
                    {
                        GLClaimType CurrentClaimType = (GLClaimType)ResultCollection[x];

                        DataRow ResultRow = this.ResultTable.NewRow();

                        ResultRow[this.CurPageDataObj.InternalID] = CurrentClaimType.InternalID;                        
                        ResultRow[this.CurPageDataObj.Code] = CurrentClaimType.GLCode;
                        ResultRow[this.CurPageDataObj.DurationInString] = ClaimManager.GetClaimTypeLimitDurationInString(CurrentClaimType.LimitDuration);
                        ResultRow[this.CurPageDataObj.Currency] = CurrentClaimType.ClaimLimitCurrency;
                        ResultRow[this.CurPageDataObj.LimitAmount] = CurrentClaimType.ClaimLimit;
                        ResultRow[this.CurPageDataObj.LimitAmountInStr] = CurrentClaimType.ClaimLimit.ToString(GonzalesGeneralVariables.CurrencyFormat);
                        ResultRow[this.CurPageDataObj.Strict] = (CurrentClaimType.Strict)?"<img src='" + GonzalesImages.Icon_Checked + "'>":"";
                        ResultRow[this.CurPageDataObj.ExpenseDetail] = CurrentClaimType.DisplayName;
                        if (this.CurrentPrivateSession.CurrentLoggedOnUser.IsFinanceAdmin)
                        {
                            if (this.CurrentPrivateSession.CurrentLoggedOnUser.IsFinancialManager)
                            {
                                ResultRow[this.CurPageDataObj.EditLink] = "<a href='" + CurrentClaimType.InternalID + "' class='GridViewLink'>Edit</a>";
                                ResultRow[this.CurPageDataObj.DeleteLink] = "<a class='GridViewLink' href='GonzalesAdminEEDLDetail.aspx?DELETE=TRUE&id=" + this.ClaimantID + "&did=" + CurrentClaimType.InternalID + "' onclick=\"return confirm('This action will not able to be undone, continue?');\">Delete</a>";
                            }
                        }
                        else if (this.CurrentPrivateSession.CurrentLoggedOnUser.IsPowerAdmin || this.CurrentPrivateSession.CurrentLoggedOnUser.IsITAdmin) // thangnv added 20130522
                        {
                            ResultRow[this.CurPageDataObj.EditLink] = "<a href='" + CurrentClaimType.InternalID + "' class='GridViewLink'>Edit</a>";
                            ResultRow[this.CurPageDataObj.DeleteLink] = "<a class='GridViewLink' href='GonzalesAdminEEDLDetail.aspx?DELETE=TRUE&id=" + this.ClaimantID + "&did=" + CurrentClaimType.InternalID + "' onclick=\"return confirm('This action will not able to be undone, continue?');\">Delete</a>";
                            this.GridViewResult.Columns[this.GridViewResult.Columns.Count - 1].Visible = false; // Delete Hyperlink button
                        }
                        else
                        {
                            ResultRow[this.CurPageDataObj.EditLink] = "<a href='" + CurrentClaimType.InternalID + "' class='GridViewLink'>Edit</a>";
                            ResultRow[this.CurPageDataObj.DeleteLink] = "<a class='GridViewLink' href='GonzalesAdminEEDLDetail.aspx?DELETE=TRUE&id=" + this.ClaimantID + "&did=" + CurrentClaimType.InternalID + "' onclick=\"return confirm('This action will not able to be undone, continue?');\">Delete</a>";                        
                        }
                        this.ResultTable.Rows.Add(ResultRow);
                    }
                }
                else
                {
                    this.ShowErrorMessage(this.FailedLoadMessage);
                    this.CurLogManager.LogError("[GonzalesAdminEEDLDetail.LoadData] : Failed at  CurManager.GetClaimTypeLimitByClaimant() : " + CurManager.ErrorMessage, this.CurrentPrivateSession.CurrentLoggedOnUser, LogInterface.System);
                }
            }

        }

    }
    #endregion

    #region DataValidate
    protected bool DataValidate()
    {
        bool smooth = true;
        StringBuilder ErrorMessages = new StringBuilder("<ul>");

        if (this.ClaimantID.Length != 36)
        {
            smooth = false;
            ErrorMessages.AppendLine("<li>" + this.ClaimantMessage + "</li>");
        }

        decimal tmp = 0;
        if (!decimal.TryParse(this.TextBox_AmountLimit.Text, out tmp) || tmp < 0)
        {
            smooth = false;
            ErrorMessages.AppendLine("<li>" + this.LimitAmountMessage + "</li>");
        }

        // check if having duplicate entry
        if (this.ResultTable != null)
        {
            foreach (DataRow ResultRow in this.ResultTable.Rows)
            {
                if (ResultRow[this.CurPageDataObj.InternalID].ToString().CompareTo(this.DropDownList_ExpenseDetail.SelectedValue) == 0)
                {
                    smooth = false;
                    ErrorMessages.AppendLine("<li>" + this.DuplicateMessage + "</li>");
                    break;
                }
            }
        }

        ErrorMessages.AppendLine("</ul>");

        if (!smooth) this.ShowErrorMessage(ErrorMessages.ToString());

        return smooth;
    }
    #endregion

    #region DataDelete
    protected void DataDelete()
    {
        bool smooth = true;
        if (this.CurrentPrivateSession.CurrentLoggedOnUser.IsPowerAdmin) return; // thangnv added 20130522

        if (Request.QueryString["id"] != null && Request.QueryString["id"].Length == 36 &&
            Request.QueryString["DELETE"] != null && Request.QueryString["DELETE"].CompareTo("TRUE") == 0 &&
            Request.QueryString["did"] != null && Request.QueryString["did"].Length == 36)
        {
            this.ClaimantID = Request.QueryString["id"];

            using (GLClaimTypeManager CurManager = new GLClaimTypeManager(this.CurrentPrivateSession))
            {
                smooth = CurManager.DeleteClaimTypeLimit(this.ClaimantID, Request.QueryString["did"]);

                if (!smooth)
                {
                    this.CurLogManager.LogError("[GonzalesAdminEEDLDetail.DataDelete] : Failed at CurManager.DeleteClaimTypeLimit('" + this.ClaimantID + "', Request.QueryString['" + Request.QueryString["did"] + "']) : ", this.CurrentPrivateSession.CurrentLoggedOnUser, LogInterface.System);
                    this.ShowErrorMessage(this.DeletionFailedMessage);
                }
            }

            if (smooth)
            {
                // log down the history
                this.CurLogManager.LogMessage("[GonzalesAdminEEDLDetail] : Exception Expense (" + Request.QueryString["did"] + ") deleted for Claimant(" + this.ClaimantID + ")", this.CurrentPrivateSession.CurrentLoggedOnUser, LogInterface.User);


                Response.Redirect("GonzalesAdminEEDLDetail.aspx?id=" + this.ClaimantID);
            }            
        }
    }

    #endregion

    private void BindData(DataView result)
    {
        this.GridViewResult.DataSource = result;
        this.GridViewResult.DataBind();
    }

    private void BindData(DataView result, int pageindex)
    {
        this.GridViewResult.PageIndex = pageindex;
        this.GridViewResult.DataSource = result;
        this.GridViewResult.DataBind();
    }

    #endregion

    #region Class: DataObj

    protected class DataObj
    {
        public readonly string InternalID = "InternalID";
        public readonly string Category = "Category";
        public readonly string Code = "Code";
        public readonly string ExpenseDetail = "ExpenseDetail";
        public readonly string DurationInString = "DurationInString";
        public readonly string Strict = "Strict";
        public readonly string Currency = "Currency";
        public readonly string LimitAmount = "LimitAmount";
        public readonly string LimitAmountInStr = "LimitAmountInStr";
        public readonly string EditLink = "EditLink";
        public readonly string DeleteLink = "DeleteLink";
    }

    #endregion

}
